package com.jz.thread;

import java.util.concurrent.DelayQueue;
import java.util.concurrent.Executor;

public class MyThread implements Runnable {
	
	private DelayQueue<Task> delayQueue;
	
	private Executor executor;
	
	public void setExecutor(Executor executor) {
		this.executor = executor;
	}

	public void setDelayQueue(DelayQueue<Task> delayQueue) {
		this.delayQueue = delayQueue;
	}

	
	public void addTask(Task t){
		this.delayQueue.add(t);
	}
	
	public void run() {
		while(true && !Thread.interrupted()){
			try {
				Task t = delayQueue.take();
				executor.execute(t);
				//Thread.sleep(1000);
			} catch (InterruptedException e) {
				e.printStackTrace();
			}
		}
		

	}

}
